package com.hula.loan4u;

import android.app.Application;
import android.content.Context;

import com.hula.loan4u.utils.BmobAppUpdateUtil;
import com.hula.loan4u.utils.LogUtil;
import com.hula.loan4u.utils.UmengUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

public class MApplication extends Application {
    public static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        if (BuildConfig.DEBUG) {
            LogUtil.mIsShowLog = true;
            UmengUtil.setDebug();
        }
        UmengUtil.init(this);
        BmobAppUpdateUtil.initBmob(this, "0a357e5e2af6fed70fea68cf07e1847f", false);
        initOkhttpClient();
    }


    private void initOkhttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addNetworkInterceptor(interceptor);
        }
        builder.connectTimeout(15, TimeUnit.SECONDS);
        builder.readTimeout(15, TimeUnit.SECONDS).hostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        OkHttpUtils.initClient(builder.build());
    }

}
